package com.dragon.logical.service.avttendance.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.logical.service.avttendance.ISiteService;
import com.dragon.repository.entity.ArrangePersonnel;
import com.dragon.repository.entity.Site;
import com.dragon.repository.mapper.ArrangePersonnelMapper;
import com.dragon.repository.mapper.SiteMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * <p>
 * 位置表 服务实现类
 * </p>
 *
 * @author sy
 * @since 2023-08-28
 */
@Service
public class SiteServiceImpl extends ServiceImpl<SiteMapper, Site> implements ISiteService {

    @Autowired
    private SiteMapper siteMapper;
    @Autowired
    private ArrangePersonnelMapper personnelMapper;

    @Override
    public Page<Site> getList(Integer adminId, String search, Integer page, Integer limit) {
        Page<Site> sitePage = new Page<>(page, limit);
        return siteMapper.selectByName(sitePage,adminId,search);
    }

    @Override
    public void add(Site site) {
        site.setCreateTime(DateUtil.date());
        siteMapper.insert(site);
    }

    @Override
    public boolean judgementPerson(Integer adminId) {
        ArrangePersonnel personnel = personnelMapper.selectOne(
                new LambdaQueryWrapper<ArrangePersonnel>().eq(ArrangePersonnel::getAdminId, adminId)
        );
        if(personnel!=null){
            return true;
        }
        return false;
    }
}
